// const BASE_URL = "http://106.55.61.224:8080"
const BASE_URL = "http://8.129.69.170:8080/"
// let token = uni.getStorageSync('token')
 function request({url,method,data,headers}){
   return new Promise((resolve, reject) => {
	   // if(!uni.getStorageSync('token')){
		  //  uni.showToast({
		  //  	title:'未授权'
		  //  })
	   // }
     // 开启loading
     // uni.showLoading({
     //   title: '正在加载~',
     //   mask: true
     // })
	console.log('4444',uni.getStorageSync('token'))
	let token = uni.getStorageSync('token')
     uni.request({
       url: BASE_URL + url,
       method: method || 'GET',
       data: data,
	   header:{
		   Authorization:token,
		  'content-type': headers || 'application/json' // 默认值
	   },
       success: (res) => {
		   console.log('res',res);
         console.log('请求',res.data);
 
         let {code,msg} = res.data
		 if(code==400){
		 		uni.showModal({
		 			 title:msg,
		 					 duration: 1500
		 		})
		   return
		 }
		 if(code==401){
			 uni.showToast({
			 	title:'token失效'
			 })
			uni.reLaunch({
			 	url:'/pages/public/login'
			 })
			 return
		 }
		 if(code==403){
		 		uni.showModal({
		 			 title:msg,
		 			 duration: 1500
		 		})
		   return
		 }
		
         if (code == 200) {
           resolve(res.data)
		   return
         }
		 
		 reject(res)
		 
       },
       // 结束关闭loading
       complete: (res) => {
		   console.log('complete',res)
         // uni.hideLoading()
       },
     })
 
   })
 
 
 
 }
 export default request